//
//  SNPersonSetViewController.m
//  project
//
//  Created by 圆圆陈 on 2018/1/20.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNPersonSetViewController.h"
#import "BirthdayPickerView.h"
#import "HeightPickerView.h"
#import "WeightPickerView.h"
#import "GenderPickerView.h"
#import "TargetPickerView.h"
#import "BlueToothViewController.h"
#import <Photos/Photos.h>
@interface SNPersonSetViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIGestureRecognizerDelegate,UIAlertViewDelegate>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UIButton *headImageBtn;
@property(nonatomic,strong)UITextField *textF;
@property(nonatomic,strong)UILabel *BMILabel;
@property(nonatomic,strong)UIButton *saveBtn;
@property(nonatomic,strong)NSArray *titleArr1;
@property(nonatomic,strong)NSArray *titleArr2;
@property(nonatomic,strong)NSArray *titleArr3;
@property(nonatomic,strong)NSArray *valueArr1;
@property(nonatomic,strong)NSArray *valueArr2;
@property(nonatomic,strong)NSArray *valueArr3;
@property(nonatomic,assign)NSInteger gender;
@property(nonatomic,strong)NSString *birthday;
@property(nonatomic,strong)NSString *BMI;
@property(nonatomic,assign)NSInteger height;
@property(nonatomic,assign)float weight;
@property(nonatomic,strong)NSString *weightTime;
@property(nonatomic,assign)NSInteger target;
@property(nonatomic,strong)UIImagePickerController *picker;
@property(nonatomic,strong)UIImage *image;
@property(nonatomic,strong)UIAlertView *alert;
@property(nonatomic,strong)UIImagePickerController *imagePickerController;
@end

@implementation SNPersonSetViewController
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *StateView = [[UIView alloc] init];
    StateView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, 20);
    StateView.backgroundColor = BBIGSTATECOLOR;
    [self.view addSubview:StateView];
    
    UIView *naView = [[UIView alloc] init];
    naView.frame = CGRectMake(0, 20+FitSimpleIpx(0, 20), kSCREEN_WIDTH, 44);
    naView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:naView];
    
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20),screenWidth, 44)];
    lable.textColor=[UIColor blackColor];
    lable.font=SNFONT(17);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text = HHH_Text(@"个人设置");
    
    [self.view addSubview:lable];
    
    UIButton *leftButton = [[UIButton alloc] init];
    leftButton.frame = CGRectMake(5, 20+FitSimpleIpx(0, 20), 44, 44);
    [leftButton setImageNormal:@"进入"];
    [leftButton addTarget:self action:@selector(leftbuttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, HHHWIDTH, HHHWIDTH/3+20)];
    _headImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _headImageBtn.frame = CGRectMake(0, 0, HHHWIDTH/3, HHHWIDTH/3);
    _headImageBtn.center = headView.center;
    _headImageBtn.layer.cornerRadius = HHHWIDTH/6;
    _headImageBtn.clipsToBounds = YES;
    if(SN_USER.portrait.length > 0)
    {
         _headImageBtn.image = SN_USER.headImage;
    }
    else
    {
        _headImageBtn.image = [UIImage imageNamed:@"loginhead"];
    }

    [_headImageBtn addTouchUpTarget:self action:@selector(getHeadImage)];
    [headView addSubview:_headImageBtn];
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, HHHWIDTH, 84)];
    _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _saveBtn.frame = CGRectMake(10, 30, HHHWIDTH-20, 44);
    _saveBtn.layer.cornerRadius = 5;
    _saveBtn.clipsToBounds = YES;
    if (KK_ShareData.loginNickName)
    {
          [_saveBtn setTitleNormal:HHH_Text(@"保存")];
    }
    else
    {
          [_saveBtn setTitleNormal:HHH_Text(@"下一步")];
    }
    [_saveBtn setTitleColorNormal:SNCOLORWHITE];
    [_saveBtn setBackgroundColor:SNCOLORBLACK];
    [_saveBtn addTouchUpTarget:self action:@selector(saveBtnClick:)];
    [footView addSubview:_saveBtn];
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20)+44+2, HHHWIDTH, HHHHEIGHT-20-FitSimpleIpx(0, 20)-44-2) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource =self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.tableHeaderView = headView;
    _tableView.tableFooterView = footView;
    [self.view addSubview:_tableView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouch)];
    tap.delegate = self;
    [self.view addGestureRecognizer:tap];
    
    
    _titleArr1 = @[HHH_Text(@"昵称"),HHH_Text(@"性别"),HHH_Text(@"出生年份")];
    _titleArr2 = @[HHH_Text(@"身高"),HHH_Text(@"上一次测量体重"),HHH_Text(@"BMI指数")];
    _titleArr3 = @[HHH_Text(@"每日目标")];
 
    _gender = SN_USER.gender;
    _birthday = SN_USER.birthday;
    _height = SN_USER.height;
    _weight = SN_USER.weight;
    _weightTime = SN_USER.weightTime;
    _BMI = SN_USER.BMI;
    _target = SN_USER.target_step;
    
    _valueArr1 = @[SN_USER.nickName,SN_USER.gender==2?HHH_Text(@"男"):HHH_Text(@"女"),[SN_USER.birthday substringToIndex:4]];
    NSString *height = [NSString stringWithFormat:@"%ldcm",SN_USER.height];
    NSString *weight = SN_USER.weightunitSet?[NSString stringWithFormat:@"%.1flb",SN_USER.weight*2.2]:[NSString stringWithFormat:@"%.1fkg",SN_USER.weight];
    _valueArr2 = @[height,weight,SN_USER.BMI];
    _valueArr3 = @[[NSString stringWithFormat:@"%ld%@",SN_USER.target_step,HHH_Text(@"步")]];
    
    SNShadowView *shadowLine = [[SNShadowView alloc] init];
    shadowLine.frame = SNFRAME(0,20+FitSimpleIpx(0, 20) + 44, HHHWIDTH, 0);
    [shadowLine showWithType:1];
    [self.view addSubview:shadowLine];
    
}
- (void)leftbuttonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)getHeadImage{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    [alertController addAction:[UIAlertAction actionWithTitle:HHH_Text(@"拍照") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _imagePickerController = [UIImagePickerController new];
        _imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        _imagePickerController.delegate = self;
        _imagePickerController.allowsEditing = YES;
        
        [self presentViewController:_imagePickerController animated:YES completion:nil];
        [self checkVideoStatus];
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:HHH_Text(@"从手机相册选择") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _imagePickerController = [UIImagePickerController new];
        _imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        _imagePickerController.allowsEditing = YES;
        _imagePickerController.delegate = self;
        
        [self presentViewController:_imagePickerController animated:YES completion:nil];
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:HHH_Text(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void) checkVideoStatus
{
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    switch (authStatus) {
        case AVAuthorizationStatusNotDetermined:
            //没有询问是否开启相机

            break;
        case AVAuthorizationStatusRestricted:
            //未授权，家长限制
            
            break;
        case AVAuthorizationStatusDenied:
            //未授权
            _alert = [[UIAlertView alloc] initWithTitle:SN_Text(@"相机功能被禁止，是否开启？")
                                                            message:@" " delegate:self
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:SN_Text(@"退出"),SN_Text(@"确定"), nil];
            [[UIView appearance] setTintColor:UIColorRGB(72, 72, 72)];
            [_alert show];
           
            break;
        case AVAuthorizationStatusAuthorized:
            //玩家授权
            
            break;
        default:
            break;
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }else{
        [_imagePickerController dismissViewControllerAnimated:YES completion:nil];
    }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    _headImageBtn.image = pickedImage;
    _image = pickedImage;
    _picker = picker;
    [picker dismissViewControllerAnimated:YES completion:nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return _titleArr1.count;
    }else if (section==1){
        return _titleArr2.count;
    }else{
        return _titleArr3.count;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = UIColorRGB(206, 207, 208);
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return section==2?0.01:5;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = UIColorRGB(206, 207, 208);
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (HHHHEIGHT-HHHWIDTH/3-20-6-84-64-2-FitSimpleIpx(0, 54))/7;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    CGFloat height = (HHHHEIGHT-HHHWIDTH/3-20-6-84-64-2-FitSimpleIpx(0, 54))/7;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.detailTextLabel.textColor = SNCOLORBLACK;
    cell.textLabel.font = SNFONT(15);
    cell.detailTextLabel.font = SNFONT(15);
    if (indexPath.section==0) {
        cell.textLabel.text = _titleArr1[indexPath.row];
        if (indexPath.row==0) {
            if (_textF==nil) {
                 _textF = [[UITextField alloc]initWithFrame:CGRectMake(FitW(80), 0, HHHWIDTH-FitW(140), height)];
                _textF.textAlignment = NSTextAlignmentRight;
                _textF.delegate = self;
                _textF.placeholder = SN_Text(@"你的名字");
                [_textF setTextColor:SNCOLORBLACK];
                [cell addSubview:_textF];
            }
            _textF.text = _valueArr1[indexPath.row];
        }else{
            cell.detailTextLabel.text = _valueArr1[indexPath.row];
        }
    }else if (indexPath.section==1){
        cell.textLabel.text = _titleArr2[indexPath.row];
        if (indexPath.row==2) {
            UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            detailBtn.frame = CGRectMake(90, 0, 80, height);
            [detailBtn setTitleNormal:HHH_Text(@"这是什么？")];
            detailBtn.titleLabel.font = SNFONTMIN(11.5);
            [detailBtn setTitleColorNormal:SNCOLORGRAY];
            [detailBtn addTouchUpTarget:self action:@selector(showBMIView)];
            [cell addSubview:detailBtn];
            
            if (_BMILabel==nil) {
                 _BMILabel = [[UILabel alloc]initWithFrame:CGRectMake(HHHWIDTH/2+20, 0, HHHWIDTH/2-FitW(60), height)];
                _BMILabel.textColor = SNCOLORBLACK;
                _BMILabel.textAlignment = NSTextAlignmentRight;
                [cell addSubview:_BMILabel];
            }
            _BMILabel.attributedText = [self changeLabelWithText:_valueArr2[indexPath.row]];
        }else{
            cell.detailTextLabel.text = _valueArr2[indexPath.row];
        }
    }else{
        cell.textLabel.text = _titleArr3[indexPath.row];
        cell.detailTextLabel.text = _valueArr3[indexPath.row];
    }
    if ((indexPath.section==0 && indexPath.row!=0) || (indexPath.section==1 && indexPath.row!=2) || indexPath.section==2) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 22, 22)];
        [imageView setImage:UIImageNamed(@"进入(1)")];
        cell.accessoryView =imageView;
    }

    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            
        }else if (indexPath.row==1){
            [self showGenderPickerView];
        }else{
            [self showBirthdayPickerView];
        }
    }else if (indexPath.section==1){
        if (indexPath.row==0) {
            [self showHeightPickerView];
        }else if (indexPath.row==1){
            [self showWeightPickerView];
        }else{
            
        }
    }else{
        [self showTargetPickerView];
    }
}
-(void)showGenderPickerView{
    GenderPickerView *setView = [[GenderPickerView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:setView];
    setView.gender = _gender;
    [setView animationUp];
    setView.sureButtonBlock = ^(NSString *str) {
        _valueArr1 = @[_textF.text,str,[_birthday substringToIndex:4]];
        _gender = [str isEqualToString:SN_Text(@"男")]?2:1;
        [_tableView reloadData];
    };
}
-(void)showBirthdayPickerView{
    BirthdayPickerView *setView = [[BirthdayPickerView alloc]initWithFrame:self.view.bounds ];
    [self.view addSubview:setView];
    setView.birthday = _birthday;
    [setView animationUp];
     setView.sureButtonBlock = ^(NSString *str) {
        _valueArr1 = @[_textF.text,_gender==2?SN_Text(@"男"):SN_Text(@"女"),[str substringToIndex:4]];
        _birthday = str;
        [_tableView reloadData];
    };
}
-(void)showHeightPickerView{
    HeightPickerView *setView = [[HeightPickerView alloc]initWithFrame:self.view.bounds ];
    [self.view addSubview:setView];
    setView.height = _height;
    [setView animationUp];
    setView.sureButtonBlock = ^(NSString *str) {
        NSString *height = [NSString stringWithFormat:@"%ldcm",str.integerValue];
        NSString *weight = SN_USER.weightunitSet?[NSString stringWithFormat:@"%.1flb",_weight]:[NSString stringWithFormat:@"%.1fkg",_weight];
        _height = str.integerValue;
        [self setBMIValue];
        _valueArr2 = @[height,weight,_BMI];
        [_tableView reloadData];
    };
}
-(void)showWeightPickerView{
    WeightPickerView *setView = [[WeightPickerView alloc]initWithFrame:self.view.bounds ];
    [self.view addSubview:setView];
    setView.weight = _weight;
    [setView animationUp];
    setView.sureButtonBlock = ^(NSString *str,NSString *timeStr) {
        NSString *height = [NSString stringWithFormat:@"%ldcm",_height];
        NSString *weight = SN_USER.weightunitSet?[NSString stringWithFormat:@"%.1flb",str.floatValue]:[NSString stringWithFormat:@"%.1fkg",str.floatValue];
        _weight = SN_USER.weightunitSet?str.floatValue/2.2:str.floatValue;
        _weightTime = timeStr;
        [self setBMIValue];
        _valueArr2 = @[height,weight,_BMI];
        [_tableView reloadData];
    };
}
-(void)showBMIView{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:HHH_Text(@"什么是BMI")  message:HHH_Text(@"BMI解释") preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:HHH_Text(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:HHH_Text(@"退出") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:action];
    [alertController addAction:action1];
    
    UIView *subView1 = alertController.view.subviews[0];
    UIView *subView2 = subView1.subviews[0];
    UIView *subView3 = subView2.subviews[0];
    UIView *subView4 = subView3.subviews[0];
    UIView *subView5 = subView4.subviews[0];
    
    UILabel *title = subView5.subviews[0];
    UILabel *message = subView5.subviews[1];
    title.textAlignment = NSTextAlignmentLeft;
    message.textAlignment = NSTextAlignmentLeft;
    alertController.view.tintColor = UIColorHEX(0x727272);
    [self presentViewController:alertController animated:YES completion:nil];
}
-(void)showTargetPickerView{
    TargetPickerView *setView = [[TargetPickerView alloc]initWithFrame:self.view.bounds ];
    [self.view addSubview:setView];
    setView.target = _target;
    [setView animationUp];
    setView.sureButtonBlock = ^(NSString *str) {
        _valueArr3 = @[[NSString stringWithFormat:@"%ld%@",str.integerValue,HHH_Text(@"步")]];
        _target = str.integerValue;
        [_tableView reloadData];
    };
}
-(void)saveBtnClick:(UIButton *)sender{
    if (_picker!=nil) {
        SN_USER.headImage = _headImageBtn.image;
        [SN_EveryDayModelHelp saveHeadImageToFileCacheWithImage:_image];
    }else{
        if ([SN_USER.headImage isEqual:UIImageNamed(@"loginhead")]) {
            SHOWMBProgressHUD(nil, SN_Text(@"请设置您的头像"), nil, NO, 1.0);
            return ;
        }
    }
    if (_textF.text.length<=16 && _textF.text.length>=3) {
        SN_USER.nickName = _textF.text;
    }else{
        SHOWMBProgressHUD(nil, SN_Text(@"昵称为3~16位"), nil, NO, 2);
        return;
    }
    if (SN_USER.gender!=_gender) {
        SN_USER.gender = _gender;
    }
    if (![SN_USER.birthday isEqualToString:_birthday]) {
        SN_USER.birthday = _birthday;
    }
    if (SN_USER.height!=_height) {
        SN_USER.height = _height;
    }
    if (SN_USER.weight!=_weight) {
        SN_USER.weight = _weight;
        SN_USER.weightTime = _weightTime;
    }
    if (_type==0) {
        SN_USER.weightTime = [[NSDate date] dateToDayString];
    }
    if (SN_USER.target_step!=_target) {
        SN_USER.target_step = _target;
    }
    SN_PublicClass.todaySport.stepTarget = _target;
    if (SN_PublicClass.todaySport.step >= _target)
    {
        SN_PublicClass.todaySport.stepquality = YES;
        SN_PublicClass.todaySport.stepBoolFinish = 1;
    }
    else
    {
        SN_PublicClass.todaySport.stepquality = NO;
        SN_PublicClass.todaySport.stepBoolFinish = 0;
    }
    sender.enabled = NO;
    [SN_PublicClass.todaySport updateToDB];
    
    [SN_USER updateToDB];
    if (_type==1) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        if (!KK_BLEConnect.model.isConnected) // 手环绑定界面
        {
            BlueToothViewController *blueVC = [[BlueToothViewController alloc]init];
            blueVC.type = 0;
            [self.navigationController pushViewController:blueVC animated:YES];
        }else{
            [kK_App enterMainVc];
        }
    }
    
    if (_picker!=nil) {
        [SN_Net uploadImageWithImage:_image WithSuccess:^(id object) {
            [SN_Net updateUserInfoWithSuccess:^(id object) {
                
            } fail:^(id object) {
                
            }];
        } fail:^(id object) {
            
        }];
    }else{
        [SN_Net updateUserInfoWithSuccess:^(id object) {
            
        } fail:^(id object) {
            
        }];
    }
    if (!KK_BLEConnect.isConnected) {
        SHOWMBProgressHUD(nil, SN_Text(@"设备未连接"), nil, NO, 2.0);
        return;
    }else{
        [SN_EveryDayModelHelp startUpdateUserInfo];
    }
    sender.enabled = YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    //textField.text = @"";
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (_textF.text.length==0) {
        textField.text = SN_USER.nickName;
    }
}
- (void)tapTouch
{
    [_textF resignFirstResponder];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if([NSStringFromClass([touch.view class])isEqual:@"UITableViewCellContentView"]){
        [_textF resignFirstResponder];
        return NO;
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(void )setBMIValue{
    CGFloat BMIValue = _weight*1.0/(_height*1.00/100*_height*1.00/100);
    NSString *BMIStr = [NSString string];
    if (BMIValue>=32) {
        BMIStr = HHH_Text(@"非常肥胖");
    }else if (BMIValue>=28){
        BMIStr = HHH_Text(@"肥胖");
    }else if (BMIValue>=24){
        BMIStr = HHH_Text(@"过重");
    }else if (BMIValue>=18.5){
        BMIStr = HHH_Text(@"正常");
    }else{
        BMIStr = HHH_Text(@"过轻");
    }
    _BMI = [NSString stringWithFormat:@"%.1f  %@",BMIValue,BMIStr];
}
-(NSMutableAttributedString*)changeLabelWithText:(NSString*)string
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string];
    UIFont *font = SNFONT(FitFont(15));
    for (int i = 0; i <string.length; i++) {
        unichar ch = [string characterAtIndex:i];
        NSRange range = {i, 1};
        if (!('0' <= ch && ch <= '9')) {
            [attrString addAttribute:NSFontAttributeName value:font range:range];
        }else{
            [attrString addAttribute:NSFontAttributeName value:SNFONT(FitFont(24)) range:range];
        }
    }
    return attrString;
}
@end
